package cn.edu.xmu.orderpayment.payment.microservice.wechatpayvo;

import cn.edu.xmu.orderpayment.payment.model.bo.Refund;
import cn.edu.xmu.orderpayment.payment.util.baseobject.RefundInfo;
import cn.edu.xmu.orderpayment.payment.util.retvo2baseobj.RefundQuery;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;


@Data
@NoArgsConstructor
@AllArgsConstructor
public class WeChatPayRefundRetVo implements RefundQuery {



    @Override
    public RefundInfo createRefundInfo() {
        RefundInfo refundInfo = new RefundInfo();
        refundInfo.setTradeSn(transactionId);
        refundInfo.setRefundNo(refundId);
        refundInfo.setAmount(Long.valueOf(amount.getRefund()==null?0: amount.getRefund()));
        refundInfo.setOutTradeNo(outTradeNo);
        refundInfo.setSuccessTime(successTime);
        switch (status) {
            case "SUCCESS":
                refundInfo.setState(Refund.State.PAYMENT_COMPLETED);
                break;
            case "CLOSED":
                refundInfo.setState(Refund.State.CANCELED);
                break;
            case "PROCESSING":
                refundInfo.setState(Refund.State.PENDING_PAYMENT);
                break;
            case "ABNORMAL":
                refundInfo.setState(Refund.State.PAYMENT_FAILED);
                break;
        }
        return refundInfo;
    }



    private String refundId;

    private String outRefundNo;

    private String transactionId;

    private String outTradeNo;

    private String channel;

    private String userReceivedAccount;

    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS", timezone = "GMT+8")
    private LocalDateTime successTime;

    private String status;

    private RefundAmountRetVo amount;

}
